package com.hdu.joinInMemory.repository;

import com.hdu.joinInMemory.entity.DO.Product;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Repository
public class ProductRepository {

    private static final List<Product> PRODUCTS = new ArrayList<>();

    static {
        for (int i = 0; i < 100; i++) {
            long j = i + 1;
            PRODUCTS.add(Product.builder().id(j).name("product--" + j).build());
        }
    }

    public List<Product> findProductById(List<Long> id) {
       return PRODUCTS.stream().filter(product -> id.contains(product.getId())).collect(Collectors.toList());
    }

    public Product findProductById(Long id) {
        return PRODUCTS.stream().filter(product -> product.getId().equals(id)).findFirst().orElse(null);
    }
}
